<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>

<style>
    .font-bold {
        font-size: 14px;
        margin: 20px 0;
    }
     .dis_row{
         display: flex;flex-direction: row;
     }
    .dis_column{
        display: flex;flex-direction: column;
    }
    .a_center{
        align-items: center;
    }
    .j_center{
        justify-content: center;
    }
    .discuss_top{
        background: #ffffff;margin-top: 0px;width: 100%;font-size: 16px;color: #999;
        border-bottom: 1px solid #dfdfdf;
        /* height: 150px;*/
        height: 80px;
    }
    .discuss_top_title{
        margin-top: 0px;width: 100%;color: #999;
        height: 80px;
    }
    .discuss_top_content{
        margin-top: 0px;width: 100%;color: #666;
        height: auto;
    }
    .discuss_list{
        background: #ffffff;margin-top: 0px;width: 100%;font-size: 16px;color: #999;
    }
    .discuss_buttons{
        margin-top: 0px;width: 100%;font-size: 16px;
        height: 200px;background-color: #f5f5f5;
    }
    .discuss_buttons_textarea{
        width: 85%;
        border: 1px solid #ccc;
        border-radius: 4px;
        color: #555;
        background: #ffffff;
        padding: 4px 4px;
    }
    .discuss_buttons_send{
        width: 100px;
        height: 35px;
        border-radius: 10px;
        background-color: #22ac38;
        color: #ffffff;
        text-align: center;

    }
</style>
<body class="gray-bg">
<div class="row">
    <div class="col-sm-10">
        <div class="wrapper wrapper-content project-manager">
            <h3>学生名：<label th:text="${submitMap.stuName}"></label></h3>
            <h3>作业名称：<label th:text="${submitMap.title}"></label></h3>
            <p class=" font-bold">
                <span><i class="fa fa-circle text-success"></i>
                    状态：<label th:if="${submitMap.submitStatus==0}">正常</label>
                    <label th:if="${submitMap.submitStatus==1}">通过</label>
                    <label th:if="${submitMap.submitStatus==2}">已删除</label>
                </span>
            </p>
            <p class=" font-bold">
                <span><i class="fa fa-circle text-success"></i>
                    是否阅题：<label th:if="${submitMap.isExamine==0}">未阅题</label>
                    <label th:if="${submitMap.isExamine==1}">已阅题</label>
                </span>
            </p>
            <p class=" font-bold">
                <span><i class="fa fa-circle text-success"></i>
                   学生总得分：<label th:text="${submitMap.score}"></label></span>
            </p>
            <p class=" font-bold">
                <span><h3><i class="fa fa-circle text-success"></i>作业详情：</h3>
                    <div th:each="item : ${itmsMap}" style="border-bottom: 1px solid #666;">
                        题目类型：
                        <label th:if="${item.type==0}">单选</label>
                        <label th:if="${item.type==1}">多选</label>
                        <label th:if="${item.type==2}">判断</label>
                        <label th:if="${item.type==3}">填空</label>
                        <label th:if="${item.type==4}">问答题</label><br>
                        题目内容：<label th:text="${item.topic_content}"></label><br>
                        题目选项：<label th:text="${item.options}"></label><br>
                        正确答案：<label th:text="${item.rightKey}"></label><br>
                        考生答案：<label th:text="${item.answer}"></label><br>
                        是否正确：<label th:text="${item.yesOrNo}"></label><br>
                        <label style="color: red;" th:text="'学生得分：'+${item.getScore}+' 分'"></label><br><br>

                    </div>

                </span>
            </p>
            <p class=" font-bold">
                <span><h3><i class="fa fa-circle text-success"></i>问答题（需讲师阅题）：</h3><br>
                    <input id="questionNum" type="hidden" th:value="${itmsType4MapSize}"/>
                    <div th:each="item,userStat:${itmsType4Map}" style="border-bottom: 1px solid #666;">
                        题目类型：
                        <label th:if="${item.type==0}">单选</label>
                        <label th:if="${item.type==1}">多选</label>
                        <label th:if="${item.type==2}">判断</label>
                        <label th:if="${item.type==3}">填空</label>
                        <label th:if="${item.type==4}">问答题</label><br>
                        题目内容：<label th:text="${item.topic_content}"></label><br>
                        题目选项：<label th:text="${item.options}"></label><br>
                        正确答案：<label th:text="${item.rightKey}"></label><br>
                        考生答案：<label th:text="${item.answer}"></label><br>
                         <label th:if="${submitMap.isExamine==1}" style="color: red;" th:text="'学生得分：'+${item.getScore}+' 分'"></label><br><br>


                        <label th:if="${submitMap.isExamine!=1}" style="color: green;" th:text="'题目总分：'+${item.score}+' 分'"></label><br><br>

                        <label th:if="${submitMap.isExamine!=1}" style="font-size: 18px;font-weight: bold;"> 讲师阅题：</label><br><br>

                         <input th:if="${submitMap.isExamine!=1}" style="margin-left: 40px;width: 200px;height: 50px;border: 2px solid #000" type="text" placeholder="请输入上面问答题的得分"  th:onblur="'javascript:changeValue(this, this.value,\''+${item.id}+'\', '+'\'itmsType4_'+ ${userStat.index} +'\',\''+${item.score}+'\')'" th:name="${'itmsType4_' + userStat.index}" th:id="${'itmsType4_' + userStat.index}" />
                         <label th:if="${submitMap.isExamine!=1}" style="font-size: 18px;color: red;"> 分</label>
                        <br>
                        <br>
                    </div>
                </span>
            </p>
            <div class="dis_row a_center j_center " style="width: 70%;margin-top: 30px;">
                <form  id="submitForm">
                    <input id="result" name="result" type="hidden"/>
                    <input id="type" name="type" type="hidden" value="1"/>
                    <input id="submitId" name="submitId" type="hidden" th:value="${submitMap.submitId}"/>
                </form>
                <div th:if="${submitMap.isExamine!=1}" id="submitBtn" onclick="toSubmitResult()" class="discuss_buttons_send dis_row a_center j_center ">
                    提交
                </div>
                <div th:if="${submitMap.isExamine==1}" style="display: none;" id="submitBtn" class="discuss_buttons_send dis_row a_center j_center ">
                    提交
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script src="//s.xlongwei.com/res/js/My97DatePicker/WdatePicker.js"></script>
<script>
    let valueList = [];
    function changeValue(that, value,itemId, id, itemScore) {
        console.log("value:"+value);
        console.log("itemId:"+itemId);
        console.log("id:"+id);
        if( parseInt(value) > parseInt(itemScore) || parseInt(value) < 0){
            layer.alert('请输入 >0 且 <= '+itemScore+' 的数字');
            that.val("");
        }else {
            if (valueList.length > 0) {
                let flag = false;
                for (let a = 0; a < valueList.length; a++) {
                    if (itemId == valueList[a].id) {
                        valueList[a].value = value;
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    let obj = {
                        "id": itemId,
                        "value": value
                    }
                    valueList.push(obj);
                }
            } else {
                let obj = {
                    "id": itemId,
                    "value": value
                }
                valueList.push(obj);
            }
            //console.log("valueList:" + JSON.stringify(valueList));
            $("#result").val(JSON.stringify(valueList));
        }
    }
    function toSubmitResult(){
        console.log("valueList:" + JSON.stringify(valueList));
        //判断是否阅完题
        let questionNum = $("#questionNum").val();
        if(valueList.length == parseInt(questionNum)) {
            /*ajaxToken("/jzApi/courses/submitTasksResult", 'POST',
                {
                    result: JSON.stringify(valueList),
                    type: 1,//已阅完题
                }, function (res) {
                    if (res == 1) {
                        layer.msg("问题结果已提交！");
                        $("#submitBtn").hide();
                    } else {
                        layer.msg(res);
                    }
                }
            )*/
            $.ajax({
                cache : true,
                type : "POST",
                url : "/jzweb/classesExaminationSubmit/submitClassesExaminationResult",
                data : $('#submitForm').serialize(),// 你的formid
                async : false,
                error : function(request) {
                    parent.layer.alert("Connection error");
                },
                success : function(data) {
                    if (data.code == 0) {
                        parent.layer.msg("问题结果已提交");
                        parent.reLoad();
                        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(index);

                    } else {
                        parent.layer.alert(data.msg)
                    }

                }
            });
        }else {
            layer.alert("当前页面还有“问答题”没有阅完，请阅完再提交！")
            /*layer.confirm('当前页面还有“问答题”没有阅完，确定要提交吗?', function(index){
                ajaxToken("/jzApi/courses/submitTasksResult", 'POST',
                    {
                        result: JSON.stringify(valueList),
                        type: 0,//未阅完题
                    }, function (res) {
                        if (res == 1) {
                            layer.msg("问题结果已提交，可以再次提交！");
                        } else {
                            layer.msg(res);
                        }
                    }
                )
                layer.close(index);
            });*/
        }
    }
</script>

</body>
</html>
